package com.zhuang.intelnet.qqserver.qqserver;

import java.util.HashMap;
import java.util.Iterator;

public class ManageClientThreads {
	private static HashMap<String, ServerConnectClientThread> map = new HashMap<String, ServerConnectClientThread>();

	// 返回map
	public static HashMap<String, ServerConnectClientThread> getMap() {
		return map;
	}

	// 将线程添加对象到map集合
	public static void addClientThread(String userId, ServerConnectClientThread serverConnectClientThread) {
		map.put(userId, serverConnectClientThread);
	}

	// 根据userId，返回ServerConnectClientThread线程
	public static ServerConnectClientThread getServerConnectClientThread(String userId) {
		return map.get(userId);
	}

	// 增加一个方法，从集合中，移除某个线程对象
	public static void removeServerConnectClientThread(String userId) {
		map.remove(userId);
	}

	/*
	 * 返回在线用户列表
	 */
	public static String getOnlineUser() {
		// 遍历集合
		Iterator<String> iterator = map.keySet().iterator();
		String onlineUserList = "";
		while (iterator.hasNext()) {
			onlineUserList += iterator.next().toString() + " ";
		}
		return onlineUserList;
	}
}
